#include "main.h"
#include "delay.h"
#include "user_usart.h"
#include "user_tim.h"
#include "user_gpio.h"
#include "ti_msp_dl_config.h"
#include "menu_fsm.h"
#include "./OLED/OLED.h"
#include "./tlsf/tlsf_porting.h"
#include "./lw_queue/lw_queue_porting.h"
#include "./lw_timer/lw_timer.h"
#include "./lw_timer/lw_timer_callback.h"
#include "./letter_shell/letter_shell_porting.h"
#include "./flexible_button/flexbutton_porting.h"

/********************静态变量定义********************/
static param_event_t read_event;

int main(void)
{
	/********************系统级初始化********************/
	SYSCFG_DL_init(); /*初始化系统资源*/		
	
	/********************硬件级初始化********************/
	OLED_Init();
	
	/********************框架基层初始化********************/
	memory_pool_init(); /*初始化内存池*/
	lwq_hook_set(); /*设置队列内存钩子*/
	
	/********************框架组件初始化********************/
	debug_shell_init(); /*初始化letter shell*/
	menu_fsm_init(); /*初始化菜单状态机*/
	user_button_init(); /*初始化用户按键*/
	lw_timer_set_stamp(sys_tick_get); /*载入软件定时器时基*/
	
	/********************用户级初始化********************/
	btn_scan_tim_start(); /*启动按键扫描软件定时器*/
	oled_update_tim_start(); /*启动OLED刷新任务软件定时器*/
	letter_shell_tim_start(); /*启动letter shell任务软件定时器*/
	
	/********************正式开启用户中断********************/
	debug_usart_rec_start(); /*开启调试接收*/	
	
	while(1)
	{
		if(lwq_read(&menu_fsm_que, &read_event))
		{
			menu_fsm_dispatch(&menu_fsm, &read_event);
		}

		lw_timer_scheduler(); /*执行软件定时器任务*/		
	}
}
